/******
* Isolate.cpp
*
* Extracts only the differing values in two documents and 
* returns them in a string for future use by the user
******/

#include <utility>
#include <vector>
#include <string>


template<class T> std::pair<std::string, std::string> printIsolation(std::vector<std::pair<T,T> > c, std::string textA, std::string textB)
{
	//Variables instanciated
	int i, j=0;
	bool disparityFlag = 0;
	int negOneCounter = 0;
	std::string temp = "";
	std::string isolateA = "{\\rtf1\\ansi\\deff0{\\colortbl;\\red0\\green0\\blue0;\\red255\\green200\\blue0;}";
	std::string isolateB = "{\\rtf1\\ansi\\deff0{\\colortbl;\\red0\\green0\\blue0;\\red255\\green200\\blue0;}";

//loop through the first text file and isolate the lines where disparities are found
	for (i = 0; i<textA.length(); i++)
	{
		if(textA[i] != '\\' )
		{
	      	temp += textA[i];
		}
		else
		{
			temp += '\\' + textA[i];
		}

		if (j < c.size())
		{
			if(i == (c[j].first))
			{
				disparityFlag = 1;
				j++;
			}
			else{
				if(c[j].first == -1){
					if(i== c[j].second){
						disparityFlag = 1;
						j++;
						negOneCounter++;
					}
				}
			}
		}
		if(textA[i] == '\n' || i == textA.length()-1 || textA[i] == ' ')
		{
			while(negOneCounter>0 && textA[i] != ' ')
			{
				temp += " ";
				negOneCounter--;
			}
			if(disparityFlag == 1)
			{
				isolateA+= "\\cf1 " + temp + "\\line \\line ";
			}

			disparityFlag = 0;
			temp = "";
		}

	}

	//close RTF
	isolateA += "}";
	j=0;
	disparityFlag = 0;
	
	//loop through the second text file and isolates the lines where disparities are found
	for (i = 0; i<textB.length(); i++)
	{
		if(textB[i] != '\\')
		{
	            temp += textB[i];
		}
		else
		{
			temp += '\\' + textB[i];
		}

		if( j < c.size() )
		{
			if(i == (c[j].second))
			{
				disparityFlag = 1;
				j++;
			}
			else{
				if(c[j].second == -1){
					if(i== c[j].first){
						disparityFlag = 1;
						j++;
						negOneCounter++;
					}
				}
			}
		}
		if(textB[i] == '\n' || i == textB.length()-1 || textB[i] == ' ')
		{
			while(negOneCounter>0 && textB[i] != ' ')
			{
				temp += " ";
				negOneCounter--;
			}
			if(disparityFlag == 1)
			{
				isolateB+= "\\cf1 " + temp + "\\line \\line ";
			}

			disparityFlag = 0;
			temp = "";
		}

		
	}
	//close RTF
	isolateB += "}";

	return std::make_pair(isolateA,isolateB);
}
